import { Component, OnInit } from '@angular/core';
import { ApiService } from '../../../../providers/ApiPro.service';
import { parts , optionCarStatus, optionCarCategory} from '../HuoRestmp.model';


@Component({
  selector: 'app-ResCarlist',
  templateUrl: './ResCarlist.component.html',
  styleUrls: ['./ResCarlist.component.scss']
})
export class ResCarlistComponent implements OnInit {
  public data = [];
  public _total = 0;
  public pageIndex = 1;
  public parts: parts = new parts();
  public once = true;//时间转换格式的时候一个判断，防止二次转换出现BUG
  public createTime:string = null;
  public optionCarCategory = optionCarCategory;

  constructor(
    public apiService: ApiService,    
  ) { }

  public optionCarStatus  = optionCarStatus;

  ngOnInit() {
    this.loadAll();
  }

  loadAll(){
    let url = "car/findlist";
    //下面的if语句是因为组件的删除会有一个null值残留，影响get请求。
    if(this.createTime){
      this.parts.createTime=this.apiService.formatDateTime2(this.createTime);
    }else if(!this.createTime){
      delete this.parts.createTime;
    }
    if(!this.parts.carNo){
      delete this.parts.carNo;    
    }
    if(!this.parts.carCategory){
      delete this.parts.carCategory;    
    }
    if(!this.parts.carStatus){
      delete this.parts.carStatus;
    }
    console.log(this.parts);
    this.apiService.get(url,this.parts)
      .then(res =>{
        console.log(res);
        this._total = res.totalCount;
        this.data = res.result;
      })
  }

  resetIndex(e) {
        this.parts.setPage(e);
        this.loadAll();
  }
}
